//
//  AppNetwork+Album.m
//  XiaoMiao
//
//  Created by 23 on 2018/2/6.
//  Copyright © 2018年 smallyou. All rights reserved.
//

#import "AppNetwork+Album.h"
#import "XMCameraAngleModel.h"
#import "XMUploadPhotoModel.h"

@implementation AppNetwork (Album)
/**获取图库*/
+ (void)album_getLibraryWithPartyId:(NSString *)partyId completion:(void(^)(BOOL success, id response, NSString *errMsg))completion
{
    //拼接参数
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"partyId"] = partyId;
    
    [self getWithUrl:kGetAlbumLibraryPath refreshCache:NO params:parameters success:^(id response) {
        
        if (completion) {
            completion(YES, response, nil);
        }
        
    } fail:^(AppError *error) {
        if (completion) {
            completion(NO, nil, [error errorMessage]);
        }
    }];
    
}

/**获取拍照的角度*/
+ (void)album_getCameraAngleWithCateId:(NSString *)cateId
                             subCateId:(NSString *)subCateId
                          subSubCateId:(NSString *)subSubCateId
                              realName:(NSString *)realName
                            completion:(void(^)(BOOL success, NSArray<XMCameraAngleModel *> *angles, AppError *error))completion
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"cateId"] = cateId;
    param[@"subCateId"] = subCateId;
    param[@"subSubCateId"] = subSubCateId;
    param[@"realName"] = realName;
    
    [self getWithUrl:kGetAnglePath refreshCache:NO params:param success:^(id response) {
        
        NSArray *photoAngleTemplateViews = response[@"photoAngleTemplateViews"];
        NSArray *arrayM = [XMCameraAngleModel mj_objectArrayWithKeyValuesArray:photoAngleTemplateViews];
        
        if (completion) {
            completion(YES, arrayM, nil);
        }
        
        
    } fail:^(AppError *error) {
        
        if (completion) {
            completion(NO, nil, error);
        }
    }];
}

/**上传拍照结果*/
//+ (void)camera_uploadPhotoWitType:(XMUploadPhotoType)type withModel:(XMUploadPhotoModel *)upModel completion:(void(^)(BOOL success, AppError *error))completion
//{
//    //拼接参数
//    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
//    parameters[@"cateId"] = upModel.cateId;
//    parameters[@"subCateId"] = upModel.subCateId;
//    parameters[@"subSubCateId"] = upModel.subSubCateId;
//    parameters[@"templateId"] = upModel.templateId;
//    parameters[@"photographUserAngleJson"] = upModel.photographUserAngleJson;
//    
//    if (type == XMUploadPhotoTypeNew) {
//        //新增
//        parameters[@"age"] = @(upModel.age);
//        if (upModel.city.length) {
//            parameters[@"city"] = upModel.city;
//        }
//        if (upModel.realName.length) {
//            parameters[@"realName"] = upModel.realName;
//        }
//        if (upModel.sex.length) {
//            parameters[@"sex"] = upModel.sex;
//        }
//        if (upModel.phone.length) {
//            parameters[@"phone"] = upModel.phone;
//        }
//        if (upModel.province.length) {
//            parameters[@"province"] = upModel.province;
//        }
//        if (upModel.city.length) {
//            parameters[@"city"] = upModel.city;
//        }
//        
//    }else{
//        parameters[@"partyId"] = upModel.partyId;
//    }
//    
//    
//    [self postWithUrl:kUploadCameraPhotoPath params:parameters success:^(id response) {
//        
//        if (completion) {
//            completion(YES, nil);
//        }
//        
//    } fail:^(AppError *error) {
//        
//        if (completion) {
//            completion(NO, error);
//        }
//        
//    }];
//    
//}

+ (AppURLSessionTask *)album_uploadPhotoAndInfoWithModel:(XMUploadPhotoModel *)model completion:(void(^)(BOOL success, NSString *errorMsg))completion
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"cateId"]        = model.cateId;
    param[@"subCateId"]     = model.subCateId;
    param[@"subSubCateId"]  = model.subSubCateId;
    
    param[@"age"]           = model.baseInfoModel.age;
    param[@"province"]      = model.baseInfoModel.province;
    param[@"city"]          = model.baseInfoModel.city;
    param[@"phone"]         = model.baseInfoModel.phone;
    param[@"profile"]       = model.baseInfoModel.profile;
    param[@"realName"]      = model.baseInfoModel.realName;
    param[@"sex"]           = model.baseInfoModel.sex;
    
    param[@"partyId"]       = model.partyId;
    param[@"photographUserAngleJson"] = model.photographUserAngleJson;
     
    AppURLSessionTask *task = [AppNetwork postWithUrl:kUploadPhotoAndInfoPath params:param success:^(id response) {
        if (completion) {
            completion(YES, nil);
        }
    } fail:^(AppError *error) {
        if (completion) {
            completion(NO, [error errorMessage]);
        }
    }];
    
    return task;
}


/**检测新创建用户名字*/
+ (AppURLSessionTask *)album_CheckUserNameWithrealName:(NSString *)realName completion:(void(^)(BOOL success,NSString * partyId, NSString *errorMsg))completion{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    
    LoginInfoModel * loginModel = [LoginInfoModel getLoginInfo];
    [param setValue:realName forKey:@"realName"];
    [param setValue:loginModel.id forKey:@"partyId"];

    AppURLSessionTask *task = [AppNetwork getWithUrl:kCheckUserRealyNamePath refreshCache:NO params:param success:^(id response) {
        
        if (completion) {
            completion(YES,nil, nil);
        }
        
    } fail:^(AppError *error) {
        
        NSDictionary * responseDic = error.response;
        NSString * idStr;
        if (responseDic) {
            NSDictionary *partyView2 = responseDic[@"partyView2"];
            idStr = partyView2[@"id"];
        }
        

        if (completion) {
            completion(NO,idStr,[error errorMessage]);
        }
        
    }];
    
    return task;
}


/**------V2-------获取拍照默认角度*/
+ (void)album_V2GetCameraAngleNormalWithrealName:(NSString *)realName
                            completion:(void(^)(BOOL success, KV2CameraAngleNormalModel * model , AppError *error))completion
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:realName forKey:@"realName"];
    
    [self getWithUrl:kV2GetAnglePath refreshCache:NO params:param success:^(id response) {
        //一级分类
        NSArray *cateViews = response[@"cateViews"];
        
        NSArray *cateViewsM = [KV2GetCameraAngleCateModel mj_objectArrayWithKeyValuesArray:cateViews];
        //二级分类
        NSArray *cateViewsSub = response[@"cateViewsSub"];
        NSArray *cateViewsSubM = [KV2GetCameraAngleCateModel mj_objectArrayWithKeyValuesArray:cateViewsSub];
        //角度
        NSArray *AngleViews = response[@"photoAngleTemplateViews"];
        NSArray *AngleViewsM = [KV2CameraAngleModel mj_objectArrayWithKeyValuesArray:AngleViews];
        
        KV2CameraAngleNormalModel * normalModel = [[KV2CameraAngleNormalModel alloc]init];
        normalModel.cateViews = cateViewsM;
        normalModel.cateViewsSub = cateViewsSubM;
        normalModel.photoAngleTemplateViews = [NSMutableArray arrayWithArray:AngleViewsM];
        
        if (completion) {
            completion(YES, normalModel, nil);
        }
        
        
    } fail:^(AppError *error) {
        
        if (completion) {
            completion(NO, nil, error);
        }
    }];
}


/**------V2-------根据上一级获取下一级数据*/
+ (void)album_V2GetCameraSubListWithParentId:(NSString *)parentId completion:(void(^)(BOOL success, NSArray * modelList , AppError *error))completion{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:parentId forKey:@"parentId"];
    [param setValue:@"2" forKey:@"dept"];
    [param setValue:@"Cosmetology" forKey:@"typeKey"];
    
    [self getWithUrl:kV2GetCameraSubListPath refreshCache:NO params:param success:^(id response) {
        //下一级分类
        NSArray *cateViews = response[@"cateViews"];
        
        NSArray *cateViewsM = [KV2GetCameraAngleCateModel mj_objectArrayWithKeyValuesArray:cateViews];
        
        if (completion) {
            completion(YES, cateViewsM, nil);
        }
        
        
    } fail:^(AppError *error) {
        
        if (completion) {
            completion(NO, nil, error);
        }
    }];
    
    
}

/**------V2-------根据分级获取拍照角度*/
+ (void)album_V2GetCameraAngleWithRealName:(NSString *)realName cateId:(NSString *)cateId subCateId:(NSString *)subCateId completion:(void(^)(BOOL success, NSMutableArray <KV2CameraAngleModel *>* models , AppError *error))completion
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:realName forKey:@"realName"];
    [param setValue:cateId forKey:@"cateId"];
    [param setValue:subCateId forKey:@"subCateId"];

    
    [self getWithUrl:kV2GetAngleWithCatePath refreshCache:NO params:param success:^(id response) {

        //角度
        NSArray *AngleViews = response[@"photoAngleTemplateViews"];
        NSArray *AngleViewsM = [KV2CameraAngleModel mj_objectArrayWithKeyValuesArray:AngleViews];
        
        NSMutableArray * listArr = [NSMutableArray arrayWithArray:AngleViewsM];
        if (completion) {
            completion(YES, listArr, nil);
        }
        
        
    } fail:^(AppError *error) {
        
        if (completion) {
            completion(NO, nil, error);
        }
    }];
}


/**------V2-------获取项目选择分类*/
+ (void)album_V2GetProjectListWithsubCateId:(NSString *)subCateId completion:(void(^)(BOOL success, XMTypeListModel *model , AppError *error))completion
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:subCateId forKey:@"subCateId"];
    
    
    [self getWithUrl:kV2GetProjectListPath refreshCache:NO params:param success:^(id response) {
        
        
        NSArray *cateViewsM = [NSArray modelArrayWithClass:[XMTypeListClassifyModel class] json:response[@"cateViews"]];
        
        XMTypeListModel * model = [[XMTypeListModel alloc]init];
        model.cateViews = cateViewsM;
        
        if (completion) {
            completion(YES, model, nil);
        }
        
        
    } fail:^(AppError *error) {
        
        if (completion) {
            completion(NO, nil, error);
        }
    }];
}
/**------V2-------获取医美史列表*/
+ (void)album_V2GetBeautyHistorycompletion:(void(^)(BOOL success, XMTypeListModel *model , AppError *error))completion{
    
    [self getWithUrl:kV2GetBeautyHistoryPath refreshCache:NO params:nil success:^(id response) {
        
        
        NSArray *cateViewsM = [NSArray modelArrayWithClass:[XMTypeListClassifyModel class] json:response[@"cateViews"]];
        
        XMTypeListModel * model = [[XMTypeListModel alloc]init];
        model.cateViews = cateViewsM;
        
        if (completion) {
            completion(YES, model, nil);
        }
        
        
    } fail:^(AppError *error) {
        
        if (completion) {
            completion(NO, nil, error);
        }
    }];
    
}

/**------V2-------获取个人信息标签*/
+ (void)album_V2GetUserDetailTagCompletion:(void(^)(BOOL success, XMUserDetailTagListModel *model , AppError *error))completion{

    [self getWithUrl:kV2GetUserDetailTagPath refreshCache:NO params:nil success:^(id response) {
        
        //既往病史
        NSArray *medicalHistoryViews = response[@"medicalHistoryView"];
        NSArray *medicalHistoryViewsM = [XMUserDetailTagModel mj_objectArrayWithKeyValuesArray:medicalHistoryViews];
        
        //生理状况
        NSArray *physiologicalConditionViews = response[@"physiologicalConditionView"];
        NSArray *physiologicalConditionViewsM = [XMUserDetailTagModel mj_objectArrayWithKeyValuesArray:physiologicalConditionViews];
        
        XMUserDetailTagListModel * listModel = [[XMUserDetailTagListModel alloc]init];
        listModel.medicalHistoryView = medicalHistoryViewsM;
        listModel.physiologicalConditionView = physiologicalConditionViewsM;

        if (completion) {
            completion(YES, listModel, nil);
        }
        
        
    } fail:^(AppError *error) {
        
        if (completion) {
            completion(NO, nil, error);
        }
    }];
    
}

/**创建用户*/
+ (void)album_createUserDataWithModel:(XMUserCreateModel *)model completion:(void(^)(BOOL success, NSString * data, AppError *error))completion{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];

    [param setValue:model.addr forKey:@"addr"];
    [param setValue:model.age forKey:@"age"];
    [param setValue:model.cateId forKey:@"cateId"];
    [param setValue:model.city forKey:@"city"];
    [param setValue:model.extr forKey:@"extr"];
    [param setValue:model.food forKey:@"food"];
    [param setValue:model.material forKey:@"material"];
    [param setValue:model.medicalHistory forKey:@"medicalHistory"];
    [param setValue:model.medicinal forKey:@"medicinal"];
    [param setValue:model.partyId forKey:@"partyId"];
    [param setValue:model.phone forKey:@"phone"];
    [param setValue:model.photographUserAngleJson forKey:@"photographUserAngleJson"];
    [param setValue:model.physiologicalCondition forKey:@"physiologicalCondition"];
    [param setValue:model.position forKey:@"position"];
    [param setValue:model.profile forKey:@"profile"];
    [param setValue:model.project forKey:@"project"];
    [param setValue:model.province forKey:@"province"];
    [param setValue:model.realName forKey:@"realName"];
    [param setValue:model.remark forKey:@"remark"];
    [param setValue:model.sex forKey:@"sex"];
    [param setValue:model.subCateId forKey:@"subCateId"];
    [param setValue:model.subSubCateId forKey:@"subSubCateId"];
    [param setValue:model.subSubSubCateId forKey:@"subSubSubCateId"];
    [param setValue:model.subSubSubSubCateId forKey:@"subSubSubSubCateId"];
    [param setValue:model.partyRemark forKey:@"partyRemark"];

    [self postWithUrl:kCreateUserUrl params:param success:^(id response) {
        
        if (completion) {
            completion(YES, nil , nil);
        }
        
        
    } fail:^(AppError *error) {
        
        if (completion) {
            completion(NO, nil, error);
        }
    }];

    
}


/**------V2-------获取客户信息列表*/
+ (void)album_V2GetPersonDetailInfoWithPartyId:(NSString *)partyId Completion:(void(^)(BOOL success, XMNewPersonDetailModel *model , AppError *error))completion{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];

    [param setValue:partyId forKey:@"partyId"];

    
    [self getWithUrl:kV2GetPersonDetailInfoPath refreshCache:NO params:param success:^(id response) {
        
        
        XMNewPersonDetailModel * model = [XMNewPersonDetailModel modelWithJSON:response[@"partyView"]];
        
    
        if (completion) {
            completion(YES, model, nil);
        }
        
        
    } fail:^(AppError *error) {
        
        if (completion) {
            completion(NO, nil, error);
        }
    }];
    
}

/**------V2-------修改客户信息列表*/
+ (void)album_V2uploadPersonDetailInfoWithCreateModel:(XMUserCreateModel *)model Completion:(void(^)(BOOL success, XMNewPersonDetailModel *model , AppError *error))completion{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];

    
    [param setValue:model.addr forKey:@"addr"];
    [param setValue:model.age forKey:@"age"];
    [param setValue:model.city forKey:@"city"];
    [param setValue:model.extr forKey:@"extr"];
    [param setValue:model.food forKey:@"food"];
    [param setValue:model.material forKey:@"material"];
    [param setValue:model.medicalHistory forKey:@"medicalHistory"];
    [param setValue:model.medicinal forKey:@"medicinal"];
    [param setValue:model.partyId forKey:@"partyId"];
    [param setValue:model.photographUserAngleJson forKey:@"photographUserAngleJson"];
    [param setValue:model.physiologicalCondition forKey:@"physiologicalCondition"];
    [param setValue:model.position forKey:@"position"];
    [param setValue:model.profile forKey:@"profile"];
    [param setValue:model.project forKey:@"project"];
    [param setValue:model.province forKey:@"province"];
    [param setValue:model.realName forKey:@"realName"];
    [param setValue:model.sex forKey:@"sex"];
    [param setValue:model.remark forKey:@"remark"];
    [param setValue:model.phone forKey:@"phone"];

    [self postWithUrl:kV2uploadPersonDetailInfoPath params:param success:^(id response) {
        
        if (completion) {
            completion(YES, nil, nil);
        }
        
    } fail:^(AppError *error) {
        if (completion) {
            completion(NO, nil, error);
        }
    }];
    
    
}

/**------V2-------删除客户信息列表*/
+ (void)album_V2deletePersonDetailInfoWithPartyId:(NSString *)partyId doctorId:(NSString *)doctorId Completion:(void(^)(BOOL success, XMNewPersonDetailModel *model , AppError *error))completion{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    
    
    [param setValue:doctorId forKey:@"doctorId"];
    [param setValue:partyId forKey:@"partyId"];

    [self getWithUrl:kV2deletePersonDetailInfoPath refreshCache:NO params:param success:^(id response) {
        if (completion) {
            completion(YES, nil, nil);
        }
        
    } fail:^(AppError *error) {
        if (completion) {
            completion(NO, nil, error);
        }
    }];
    
    
}

/**------V2-------删除图库*/
+ (void)album_V2deletePIClistWithID:(NSString *)idStr Completion:(void(^)(BOOL success ,id responseStr, AppError *error))completion{
    
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:idStr forKey:@"id"];
    
    
    [self getWithUrl:kV2deletePICListPath refreshCache:NO params:param success:^(id response) {
        if (completion) {
            completion(YES, nil, nil);
        }
    } fail:^(AppError *error) {
        if (completion) {
            completion(NO, nil, error);
        }
    }];
}

/**------V2-------获取省市区*/
+ (void)album_V2GetProvinceCityListWithDept:(NSString *)dept     parentId:(NSString *)parentId  Completion:(void(^)(BOOL success ,NSArray * array, AppError *error))completion{
    
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setValue:dept forKey:@"dept"];
    
    param[@"parentId"] =parentId;
    [param setValue:@"CityCate" forKey:@"typeKey"];

    
    [self getWithUrl:kV2GetProvinceCityListPath refreshCache:NO params:param success:^(id response) {
        
        NSArray * listArr = [NSArray modelArrayWithClass:[AddressProvinceCityModel class] json:response[@"cateViews"]];

        
        if (completion) {
            completion(YES, listArr, nil);
        }
    } fail:^(AppError *error) {
        if (completion) {
            completion(NO, nil, error);
        }
    }];
}

@end
